package com.zws.cucumber.wiremock.listener;

import com.github.tomakehurst.wiremock.extension.StubLifecycleListener;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import com.zws.cucumber.util.ZwsMockUtil;

public class ZwsStubTimeoutMarker implements StubLifecycleListener {
    @Override
    public void beforeStubCreated(StubMapping stub) {
        if (stub.getResponse() != null
                && stub.getResponse().getFixedDelayMilliseconds() != null
                && stub.getResponse().getFixedDelayMilliseconds() > 0) {
            ZwsMockUtil.markMockedTimeout();
        }
    }

    @Override
    public void afterStubCreated(StubMapping stub) {

    }

    @Override
    public void beforeStubEdited(StubMapping oldStub, StubMapping newStub) {

    }

    @Override
    public void afterStubEdited(StubMapping oldStub, StubMapping newStub) {

    }

    @Override
    public void beforeStubRemoved(StubMapping stub) {

    }

    @Override
    public void afterStubRemoved(StubMapping stub) {

    }

    @Override
    public void beforeStubsReset() {

    }

    @Override
    public void afterStubsReset() {

    }

    @Override
    public String getName() {
        return "StubTimeoutMarker";
    }
}
